home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_pas
/
mkscren2
/
scrnctrl.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-12-08
|
10KB
|
288 lines
{procedure that centers a string on the crt screen
variable description:
Y : line on screen to center text on
str : character string to center on the screen
}
PROCEDURE crt_center(Y : integer;str : str80);
begin
gotoXY ((80-length(str)) div 2,Y);
write(str);
end;
procedure draw_title;
begin
clrscr;
bold_on;crt_center(1,'Fisher Guide Industrial Engineering Activity');bold_off;
crt_center(2,'M a n u f a c t u r i n g C o s t E s t i m a t e');
bold_on;crt_center(3,'Pre-Processing System');bold_off;
end;
{function that fills a string with specified number of characters
variable description:
cstr : character variable containing fill character
qty : integer value for quantity of characters to fill
fillstr : working string variable temporarily holding result
}
function fillstring(cstr : char;qty : integer) : str80;
var fillstr : str80;
begin
if qty < 0 then qty := 0;
fillstr[0] := chr(qty);
fillchar(fillstr[1],qty,cstr);
fillstring := fillstr;
end;
{procedure that draws an entire field definition on the screen
x : beginning horizontal position of label on the screen
y : beginning vertical position of label on screen
xf : returns horizontal beginning of field
yf : returns vertical position of field
str : the variable containing the lable to be printed
flg : a flag 0 for normal print 1 for bold printing of label
fw : the field width of the input field for this label
}
procedure draw_field(x,y : integer;var xf,yf : integer;str1,str2 : str80;flg,fw : integer);
begin
if (flg = 1) then bold_on;
gotoxy(x,y);write(output,str1,' ');
bold_off;
reverse_on;
write(str2,fillstring(' ',fw-length(str2)));
{write(output,fillstring(' ',fw));}
reverse_off;
yf := y;
xf := x + length(str1) + 1;
end;
{procedure that locates a field and allows editing of input data
s : string that is entered into current field (returned)
l : length of field
x : x coordinate of field w.r.t. to screen
y : y coordinate of field w.r.t. to screen
term : valid control characters allowed (set variable)
tc : last command entered (returned to caller)
dp : Display cursor position within field (0=no,1=yes)
underscore : constant variable containing terminal underscore
position : holds current position cursor is at within field
inchar : holds character or command typed in at console
}
procedure get_field(var s : str80;l,x,y : integer;term : charset;var tc : char;dp : integer);
const
underscore = '_';
var
position : integer;
inchar : char;
ins : boolean;
function get_char : char;
begin
result.ax := $0700;
Msdos(result);
get_char := chr(result.ax and $00FF);
end;
begin
reverse_on;
gotoxy(x,y);write(s,fillstring(underscore,l-length(s)));
position := 0;
ins := false;
gotoxy(73,24);write('OVR');
repeat
if (dp = 1) then begin gotoxy(26,10);write(position+1:2);end;
gotoxy(x+position,y);
inchar := get_char;
if (inchar = #$00) or (inchar = #$1F) then begin
inchar := get_char;
{IBM, TI, WANG ==> WordSTAR keyboard translator}
case inchar of
#75, #195 : inchar := ^S;
#77, #193 : inchar := ^D;
#71, #139, #211 : inchar := ^A;
#79, #138, #209 : inchar := ^F;
#83, #199 : inchar := ^G;
#68, #56 , #215 : inchar := ^Y;
#72, #192 : inchar := ^E;
#80, #194 : inchar := ^X;
#73, #136, #208 : inchar := ^T;
#81, #137, #210 : inchar := ^B;
#59, #128 : inchar := ^C;
#60, #129 : inchar := ^L;
#61, #200 : inchar := ^J;
#62, #201 : inchar := ^K;
#82, #198 : inchar := ^V;
#224 : inchar := #27;
end;
end;
case inchar of
#32..#126 : if position < l then
begin
position := position + 1;
if (not ins) and (position <= length(s)) then begin
s[position] := inchar;
end
else begin
if length(s) = l then
delete(s,l,1);
insert(inchar,s,position);
end;
write(copy(s,position,l));
end
else begin
error(1,5,' No additional characters allowed ');
reverse_on;
end;
^S : if position > 0 then
position := position - 1
else begin
error(1,5,' Cannot move further LEFT ');
reverse_on;
end;
^D : if position < length(s) then
position := position + 1
else begin
error(1,5,' Cannot move further RIGHT ');
reverse_on;
end;
^A : position := 0;
^F : position := length(s);
^G : if position < length(s) then
begin
delete(s,position+1,1);
write(copy(s,position+1,l),underscore);
end;
^H,#127 : if position > 0 then
begin
delete(s,position,1);
write(^H,copy(s,position,l),underscore);
position := position - 1;
end
else begin
error(1,5,' No character to delete ');
reverse_on;
end;
^Y : begin
write(fillstring(underscore,length(s)-position));
delete(s,position+1,l);
end;
^V : begin
ins := not ins;
gotoxy(73,24);
if (ins) then write('INS') else write('OVR');
end;
else
if not(inchar in term) then begin
error(1,5,' Not a valid command ');
reverse_on;
end;
end;
until inchar in term;
position := length(s);
gotoxy(x+position,y);
write('':l-position);
tc := inchar;
reverse_off;
end;
function integer_check(var input_string : str80;capstr,rjustify,fc : char;fw : integer): boolean;
var testnum : integer;
error_code : integer;
begin
integer_check := false;
if (answer in [#27,^E]) then integer_check := true else begin
if (upcase(capstr) = 'Y') then capitalize(input_string);
if (upcase(rjustify) = 'Y') then input_string := rjust(input_string,fc,fw);
val(input_string,testnum,error_code);
if (error_code <> 0) then begin
input_String := '';
error(1,5,' Input is not Numeric ') end else
if (input_string = '') then begin
error(1,5,' Input to this field is MANDATORY ');
end else integer_check := true;
end;
end;
function real_check(var input_string : str80;capstr,rjustify,fc : char;fw : integer): boolean;
var testnum : real;
error_code : integer;
begin
real_check := false;
if (answer in [#27,^E]) then real_check := true else begin
if (upcase(capstr) = 'Y') then capitalize(input_string);
if (upcase(rjustify) = 'Y') then input_string := rjust(input_string,fc,fw);
val(input_string,testnum,error_code);
if (error_code <> 0) then begin
input_string := '';
error(1,5,' Input is not Numeric ') end else
if (input_string = '') then begin
error(1,5,' Input to this field is MANDATORY ');
end else if (pos('.',input_string) = 0) then begin
input_string := '';
error(1,7,' The real number you have entered has no DECIMAL POINT ')
end else real_check := true;
end;
end;
function string_check(var input_string : str80;capstr,rjustify,fc : char;fw : integer): boolean;
begin
string_check := false;
if (answer in [#27,^E]) then string_check := true else
if (input_string = '') then error(1,5,' Input to this field is MANDATORY ') else begin
if (upcase(capstr) = 'Y') then capitalize(input_string);
if (upcase(rjustify) = 'Y') then input_string := rjust(input_string,fc,fw);
string_check := true;
end;
end;
function list_check(var input_string : str80;list : str80;
supperr,capstr,rjustify,fc : char;fw : integer): boolean;
var done : boolean;
found : boolean;
p2 : integer;
wlist : str80;
begin
list_check := false;
if (answer in [#27,^E]) then list_check := true else begin
if (upcase(capstr) = 'Y') then capitalize(input_string);
if (upcase(rjustify) = 'Y') then input_string := rjust(input_string,fc,fw);
if (input_string = '') then error(1,5,' Input to this field is MANDATORY ') else
begin
p2 := 1;
done := false;
found := false;
wlist := list;
repeat
p2 := pos(',',wlist);
if (p2 = 0) then begin p2 := length(wlist)+1;done := true;end;
if (input_string = copy(wlist,1,p2-1)) then begin
list_check := true;
found := true;
done := true;
end else delete(wlist,1,p2);
until done;
if not (found) and (supperr = 'N') then begin
input_string := '';
error(1,7,concat(' Valid options are: ',list));
end;
end;
end;
end;
function num_check(var input_string : str80;capstr,rjustify,fc : char;fw : integer): boolean;
var testnum : real;
error_code : integer;
begin
num_check := false;
if (answer in [#27,^E]) then num_check := true else begin
if (upcase(capstr) = 'Y') then capitalize(input_string);
if (upcase(rjustify) = 'Y') then input_string := rjust(input_string,fc,fw);
val(input_string,testnum,error_code);
if (error_code <> 0) then begin
input_string := '';
error(1,5,' Input is not Numeric ') end else
if (testnum = 0) then begin
input_string := '';
error(1,5,' Input to this field is MANDATORY ');
end else num_check := true;
end;
end;